import { h } from 'vue'
import { service } from '../../../utils/request'

const url = '/neutron_probe/yanalyser'
export default class YAnalyser {
  constructor() {
    
  }
  pageObj(data:any){
    return service({
      url: `${url}/pageObj`,
      method: 'post',
      data
    })
  }
  count4Page(data:any){
    return service({
      url: `${url}/count4Page`,
      method: 'post',
      data
    })
  }
  createObj(data:any):any{
    return service({
      url: `${url}/createObj`,
      method: 'post',
      data: this.format(data)
    })
  }
  getObjById(data:any):any{
    return service({
      url: `${url}/getObjById`,
      method: 'post',
      data
    })
  }

  updateObj(data:any):any{
    return service({
      url: `${url}/updateObj`,
      method: 'post',
      data: this.format(data)
    })
  }

  listObj(data:any):any{
    return service({
      url: `${url}/listObj`,
      method: 'post',
      data
    })
  }

  deleteObj(data:any):any{
  	const ID = this.getKey(data)
    return service({
      url: `${url}/deleteObj`,
      method: 'post',
      data: { ID }
    })
  }

  deleteObjs(data:any):any{
    return service({
      url: `${url}/deleteObjs`,
      method: 'post',
      data
    })
  }

  getDesc(obj:any) :any{
    return obj.Name
  }
  getKey(obj:any) :any{
  	return ""+obj.Token
  }
  getDescField() :any{
    return 'Name'
  }
  getKeyField(obj:any) :any{
    return ["Token"]
  }
  format(obj:any) :any{
	 if(null !== obj.Flux && undefined !== obj.Flux) {
		obj.Flux = parseFloat(""+obj.Flux)
	 }
     if(null !== obj.Load && undefined !== obj.Load) {
		obj.Load = parseFloat(""+obj.Load)
	 }
     if(null !== obj.Mat1 && undefined !== obj.Mat1) {
		obj.Mat1 = parseFloat(""+obj.Mat1)
	 }
     if(null !== obj.Mat10 && undefined !== obj.Mat10) {
		obj.Mat10 = parseFloat(""+obj.Mat10)
	 }
     if(null !== obj.Mat11 && undefined !== obj.Mat11) {
		obj.Mat11 = parseFloat(""+obj.Mat11)
	 }
     if(null !== obj.Mat12 && undefined !== obj.Mat12) {
		obj.Mat12 = parseFloat(""+obj.Mat12)
	 }
     if(null !== obj.Mat13 && undefined !== obj.Mat13) {
		obj.Mat13 = parseFloat(""+obj.Mat13)
	 }
     if(null !== obj.Mat14 && undefined !== obj.Mat14) {
		obj.Mat14 = parseFloat(""+obj.Mat14)
	 }
     if(null !== obj.Mat15 && undefined !== obj.Mat15) {
		obj.Mat15 = parseFloat(""+obj.Mat15)
	 }
     if(null !== obj.Mat16 && undefined !== obj.Mat16) {
		obj.Mat16 = parseFloat(""+obj.Mat16)
	 }
     if(null !== obj.Mat2 && undefined !== obj.Mat2) {
		obj.Mat2 = parseFloat(""+obj.Mat2)
	 }
     if(null !== obj.Mat3 && undefined !== obj.Mat3) {
		obj.Mat3 = parseFloat(""+obj.Mat3)
	 }
     if(null !== obj.Mat4 && undefined !== obj.Mat4) {
		obj.Mat4 = parseFloat(""+obj.Mat4)
	 }
     if(null !== obj.Mat5 && undefined !== obj.Mat5) {
		obj.Mat5 = parseFloat(""+obj.Mat5)
	 }
     if(null !== obj.Mat6 && undefined !== obj.Mat6) {
		obj.Mat6 = parseFloat(""+obj.Mat6)
	 }
     if(null !== obj.Mat7 && undefined !== obj.Mat7) {
		obj.Mat7 = parseFloat(""+obj.Mat7)
	 }
     if(null !== obj.Mat8 && undefined !== obj.Mat8) {
		obj.Mat8 = parseFloat(""+obj.Mat8)
	 }
     if(null !== obj.Mat9 && undefined !== obj.Mat9) {
		obj.Mat9 = parseFloat(""+obj.Mat9)
	 }
     if(null !== obj.Speed && undefined !== obj.Speed) {
		obj.Speed = parseFloat(""+obj.Speed)
	 }
     if(null !== obj.Status && undefined !== obj.Status) {
		obj.Status = parseFloat(""+obj.Status)
	 }
     if(null !== obj.TestAt && undefined !== obj.TestAt) {
		obj.TestAt = parseFloat(""+obj.TestAt)
	 }
     return obj
  }
  format4Select(obj:any):any {	
    return obj
  }
  // 字段的名称
  fields = [
    {
      title: '仪器编号',
      dataIndex: 'AnalyserNum',
      key: 'y_analyser.analyser_num',
      query: true,
      sorter: true
    },
    {
      title: '破碎站编号',
      dataIndex: 'CrushingPlant',
      key: 'y_analyser.crushing_plant',
      query: true,
      sorter: true
    },
    {
      title: '时间',
      dataIndex: 'TestAt',
      key: 'y_analyser.test_at',
      query: false,
      sorter: true
    },
    {
      title: '状态',
      dataIndex: 'Status',
      key: 'y_analyser.status',
      render: (t, itemData, item) => {
        switch (itemData) {
          case 0 : return h('span',{},'正常')
          case 1 : return h('span',{},'数据无效')
          case 2 : return h('span',{},'数值报警')
        }
      },
      query: false,
      sorter: true
    },
    {
      title: '速度',
      dataIndex: 'Speed',
      key: 'y_analyser.speed',
      query: false,
      sorter: true
    },
    {
      title: '流量',
      dataIndex: 'Flux',
      key: 'y_analyser.flux',
      query: false,
      sorter: true
    },
    {
      title: '载荷',
      dataIndex: 'Load',
      key: 'y_analyser.load',
      query: false,
      sorter: true
    },
    {
      title: 'SiO2',
      dataIndex: 'Mat1',
      key: 'y_analyser.mat1',
      query: false,
      sorter: true
    },
    {
      title: 'Al2O3',
      dataIndex: 'Mat2',
      key: 'y_analyser.mat2',
      query: false,
      sorter: true
    },
    {
      title: 'Fe2O3',
      dataIndex: 'Mat3',
      key: 'y_analyser.mat3',
      query: false,
      sorter: true
    },
    {
      title: 'CaO',
      dataIndex: 'Mat4',
      key: 'y_analyser.mat4',
      query: false,
      sorter: true
    },
    {
      title: 'MgO',
      dataIndex: 'Mat5',
      key: 'y_analyser.mat5',
      query: false,
      sorter: true
    },
    {
      title: 'K2O',
      dataIndex: 'Mat6',
      key: 'y_analyser.mat6',
      query: false,
      sorter: true
    },
    {
      title: 'Na2O',
      dataIndex: 'Mat7',
      key: 'y_analyser.mat7',
      query: false,
      sorter: true
    },
    {
      title: 'SO3',
      dataIndex: 'Mat8',
      key: 'y_analyser.mat8',
      query: false,
      sorter: true
    },
    {
      title: '预留1',
      dataIndex: 'Mat9',
      key: 'y_analyser.mat9',
      query: false,
      sorter: true,
      hide: true
    },
    {
      title: '预留2',
      dataIndex: 'Mat10',
      key: 'y_analyser.mat10',
      query: false,
      sorter: true,
      hide: true
    },
    {
      title: '预留3',
      dataIndex: 'Mat11',
      key: 'y_analyser.mat11',
      query: false,
      sorter: true,
      hide: true
    },
    {
      title: '预留4',
      dataIndex: 'Mat12',
      key: 'y_analyser.mat12',
      query: false,
      sorter: true,
      hide: true
    },
    {
      title: '预留5',
      dataIndex: 'Mat13',
      key: 'y_analyser.mat13',
      query: false,
      sorter: true,
      hide: true
    },
    {
      title: '预留6',
      dataIndex: 'Mat14',
      key: 'y_analyser.mat14',
      query: false,
      sorter: true,
      hide: true
    },
    {
      title: '预留7',
      dataIndex: 'Mat15',
      key: 'y_analyser.mat15',
      query: false,
      sorter: true,
      hide: true
    },
    {
      title: '预留8',
      dataIndex: 'Mat16',
      key: 'y_analyser.mat16',
      query: false,
      sorter: true,
      hide: true
    }
  ]
}
